package mr

//
// RPC definitions.
//
// remember to capitalize all names.
//

import (
	"fmt"
	"os"
	"strconv"
)

//
// example to show how to declare the arguments
// and reply for an RPC.
//

type ExampleArgs struct {
	X int
}

type ExampleReply struct {
	Y int
}

// Add your RPC definitions here.

type DispatchTaskArgs struct{}

type DispatchTaskReply struct {
	TaskType int         // map task: 0, reduce task: 1
	File     interface{} // map: input file name, reduce: intermediate files
	TaskId   int         // 任务id，如果id为-1，表示当前没有可执行的任务，sleep 1s
	NReduce  int
}

func (r DispatchTaskReply) String() string {
	return fmt.Sprintf("task type: %d, task id: %d, nReduce: %d,", r.TaskType, r.TaskId, r.NReduce) + fmt.Sprint(r.File)
}

type FinishTaskArgs struct {
	TaskType          int      // map task: 0, reduce task: 1
	TaskId            int      //
	IntermediateFiles []string // map任务独有
}

func (args FinishTaskArgs) String() string {
	return fmt.Sprintf("task type: %d, task id: %d, ", args.TaskType, args.TaskId)
}

type FinishTaskReply struct{}

// Cook up a unique-ish UNIX-domain socket name
// in /var/tmp, for the coordinator.
// Can't use the current directory since
// Athena AFS doesn't support UNIX-domain sockets.
func coordinatorSock() string {
	s := "/var/tmp/824-mr-"
	s += strconv.Itoa(os.Getuid())
	return s
}
